package com.itheima.exception;

import com.itheima.common.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ProjectExceptionHandler {

    //捕获程序开发者预计到的异常抛出进行处理
    @ExceptionHandler(CustomException.class)
    public R<String> doCustomException(CustomException e){
        System.err.println(e.getMessage());
        return R.error(e.getMessage());
    }

    //捕获程序开发者未预计到的异常进行处理
    @ExceptionHandler(Exception.class)
    public R<String> doException(Exception e){
        System.err.println(e.getMessage());
        return R.error(e.getMessage());
    }
}
